//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using EntLibContrib.Resource.Configuration;

namespace EntLibContrib.Resource
{
	/// <summary>
  /// This type supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
  /// Represents the process to build an instance of <see cref="IResourceProvider"/> described by a <see cref="ResourceProviderData"/> configuration object.
  /// </summary>
	public class ResourceProviderCustomFactory : AssemblerBasedCustomFactory<IResourceProvider, ResourceProviderData>
	{
		#region Fields
		/// <summary>
		/// This field supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
		/// </summary>
		private static ResourceProviderCustomFactory instance = new ResourceProviderCustomFactory();
		#endregion

		#region Properties
		/// <summary>
		/// This field supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
		/// </summary>
		/// <value>The instance.</value>
		public static ResourceProviderCustomFactory Instance
		{
			get { return instance; }
		}
		#endregion

		#region Protected Methods
		/// <summary>
    /// Returns the configuration object that represents the named <see cref="IResourceProvider"/> instance in the specified <paramref name="configurationSource"/>.
		/// </summary>
		/// <param name="name">The name of the required instance.</param>
		/// <param name="configurationSource">The configuration source that has the configuration object.</param>
		/// <returns>The configuration object that represents the instance with name <paramref name="name"/> in the logging 
		/// configuration section from <paramref name="configurationSource"/></returns>
		/// <exception cref="ConfigurationErrorsException"><paramref name="configurationSource"/> does not contain 
		/// resource settings, or the <paramref name="name"/> does not exist in the resource settings.</exception>
		protected override ResourceProviderData GetConfiguration(string name, IConfigurationSource configurationSource)
		{
			ResourceConfigurationView view = new ResourceConfigurationView(configurationSource);
			return view.GetResourceProviderData(name);
		}
		#endregion
	}
}
